<?php
namespace app\common\controller;

class Api extends Apicommon
{
    public  $uid = '';
    public function initialize()
    {
        parent::initialize();
        $token = input('server.HTTP_TOKEN');
        $count = db('member_user')->where(['jwt_token'=>$token])->count();
        if ($count <= 0){
            echo json_encode(array('code'=>401,'msg'=>'请登录'));die;
        }
        $checkuser = JWT::decode($token, config('jwt')['key'], array('HS256'));
        if (is_string($checkuser)) {
            $userinfo = json_decode($checkuser, true);
            $usercnt = db('member_user')->where(['id' => $userinfo['id']])->count();
            if ($usercnt <= 0) {
                echo json_encode(array('code' => 401, 'msg' => '请登录'));
                die;
            }
            $this->uid = $userinfo['id'];
            /*$check = RedisServer::lock($userinfo['id']);
            if ($check == false) {
                echo json_encode(array('code' => 400, 'msg' => '访问超时'));
                die;
            }*/
        } else {
            echo json_encode(array('code' => 400, 'msg' => $checkuser));
            die;
        }
    }
}